﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Bifrost;
using System.Xml;

namespace TextEditor.TextDocument.Data.Knowledge
{
    //知识库表
    public sealed class KnowledgeData
    {
        DataTable dtParent = null;
        DataTable dtChildren = null;

        void LoadingParent()
        {
           
            App.Ini();
            
            dtParent = App.GetDataSet("SELECT id,NAME FROM TABLE_F WHERE SHOWTYPE = '3' ORDER BY PARENTID").Tables[0];
        }

        void LoadingChildren()
        {
            dtChildren = App.GetDataSet("SELECT EVALUE,item_style,SIMPLEMETAID_F FROM TABLE_E").Tables[0];
        }

        public DataTable DtParent
        {
            get
            {
                if (dtParent == null)
                    LoadingParent();
                return dtParent;
            }
        }

        public DataTable DtChildren
        {
            get
            {
                if (dtChildren == null)
                    LoadingChildren();
                return dtChildren;
            }
        }

        public void RefreshData()
        {
            this.LoadingParent();
            this.LoadingChildren();
        }

        public bool IsLoadingDate()
        {
            return (dtChildren != null || dtChildren != null);
        }

        public void SaveDataTableToXml()
        {
            DataTable myLoadParent = App.GetDataSet("SELECT * FROM TABLE_F ORDER BY PARENTID").Tables[0];
            DataTable myLoadChild = App.GetDataSet("SELECT * FROM TABLE_E").Tables[0];
            string xmlStrParent = DataTableFromToXml.ConvertDataTableToXML(myLoadParent);
            string xmlStrChild = DataTableFromToXml.ConvertDataTableToXML(myLoadChild);
            XmlDocument document = new XmlDocument();
            document.LoadXml(xmlStrParent);
            document.Save("D://a.xml");
        }
    }
}
